package com.lanou3g.zjl.chating.home.chatwindow.child;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.lanou3g.zjl.chating.R;
import com.lanou3g.zjl.chating.utils.EmojiconUtils;
import com.lanou3g.zjl.chating.utils.SmileUtils;

import java.util.List;

/**
 * Created by dllo on 15/11/30.
 */
public class NormalExpressionGvAdapter extends BaseAdapter {
    private List<EmojiconUtils> easeEmojicon;

    public NormalExpressionGvAdapter() {

    }

    public void addData(List<EmojiconUtils> datas) {
        this.easeEmojicon = datas;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return easeEmojicon != null && easeEmojicon.size() > 0 ? easeEmojicon.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return easeEmojicon.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View v, ViewGroup viewGroup) {
        LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
        v = inflater.inflate(R.layout.normal_expression_item, null);

        NormalExpressionViewHolder holder = new NormalExpressionViewHolder(v);
        v.setTag(holder);

        EmojiconUtils emojicon = easeEmojicon.get(position);
        if (SmileUtils.DELETE_KEY.equals(emojicon.getEmojiText())) {
            holder.normalExpression_Img.setImageResource(R.mipmap.delete_expression);
        } else {
            holder.normalExpression_Img.setImageResource(emojicon.getIcon());
        }

        return v;
    }

    class NormalExpressionViewHolder {
        private ImageView normalExpression_Img;

        private NormalExpressionViewHolder(View v) {
            normalExpression_Img = (ImageView) v.findViewById(R.id.normalExpression_Img);
        }
    }
}
